import Mongoose, { Schema } from 'mongoose';
import Book from '../types/Book';

// Mongoose.Document有一些数据库的操作方法
export interface MongoBook extends Book, Mongoose.Document {}

// 泛型IArticle，帮助进行编译时的类型推断
const bookSchema = new Mongoose.Schema<MongoBook>(
    {
        // 运行时的类型
        name: String,
        author: String,
        description: String,
        publisher: String,
        pages: Number,
        price: Number,
        discountPrice: Number,
        stock: Number,
        poster: String,
        tags: [String],
        types: [String],
        publishDate: Date,
    },
    { versionKey: false },
);

// 泛型IArticle，帮助进行编译时的类型推断
export default Mongoose.model<MongoBook>('Book', bookSchema);
